package com.dongdongshop.controller;

import com.dongdongshop.common.Result;
import com.dongdongshop.domain.vo.CartVO;
import com.dongdongshop.service.CartService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("cart")
public class CartController {
    @Autowired
    private CartService cartService;

    @PostMapping("addCart")
    public Result addCart(@RequestParam Long skuId,
                          @RequestParam Integer num,
                          @RequestHeader String AutharizeToken){

        cartService.addCart(skuId,num,AutharizeToken);
        return Result.OK();
    }

    @PostMapping("selectCart")
    public Result selectCart(@RequestHeader String AutharizeToken){
        List<CartVO> cartVOList = cartService.selectCart(AutharizeToken);
        return Result.OK().setData(cartVOList);
    }
}
